//
//  Extension + UIButton.swift
//  BQWB
//
//  Created by laibingqiang on 16/10/22.
//  Copyright © 2016年 laibingqiang. All rights reserved.
//

import UIKit

extension UIButton{
    
    
    convenience init(target:Any?,action:Selector,imgName:String?,backImg:String?,title:String?){
        
        self.init()
        
        self.addTarget(target, action:action, for: UIControlEvents.touchUpInside)
        
        if title != nil {
            
            self.setTitle(title, for: UIControlState.normal)
            
            self.setTitleColor(UIColor.black, for: UIControlState.normal)
            
            self.setTitleColor(UIColor.red, for: UIControlState.highlighted)
            
            self.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        }
        
        if let img = imgName{
            
            self.setImage(UIImage(named:img), for: UIControlState.normal)
            
            self.setImage(UIImage(named:"\(img)_highlighted"), for: UIControlState.highlighted)
            
        }
        
        if backImg != nil{
            
            self.setBackgroundImage(UIImage(named:backImg!), for: UIControlState.normal)
            
            self.setBackgroundImage(UIImage(named:"\(backImg)_highlighted"), for: UIControlState.highlighted)
        }
        
        
        self.sizeToFit()

    }
    
    
}
